﻿#ifndef CPSUDPCLIENT_H
#define CPSUDPCLIENT_H

#include <QObject>
#include <QUdpSocket>
#include <QThread>
#include <QDebug>
#include <QHostAddress>
#include "QmlSignal.h"
#include <CommonHelper.h>
#include <Experiment/ExperimentThread.h>
#include <CommCommand.h>
#include <QDateTime>
#include <StaticProperties.h>
#include "animationParseHEX.h"
#include <QAbstractSocket>

//该对象最终运行在次线程中
class CpsUdpClient : public QUdpSocket
{
    Q_OBJECT
public:
    static CpsUdpClient* getInstance();
    CpsUdpClient(QObject *parent = NULL);
    ~CpsUdpClient();
public:
    void ClientConnectToHost(const QString &address, quint16 port);
    bool IsOnline();
    void ClientSendingData(const QByteArray &c_btaData);

signals:
    //转换来自主线程的链接操作
    void SignalConnectToHost(const QString & address, quint16 port);
    //在次线程中缓冲并滑动解析TCP流后/按约定格式再发布
    void SignalPublishFormatRecvData(const QString c_btaData);
    //转换来自主线程的发送操作
    void CpsSignalSendingData(const QByteArray c_btaData);


private:
    void receiveDataProcessing(QStringList);
    void onTimeout();
    void saveLog(QString,QStringList);

private:
    bool m_bOnLine = false;
    static CpsUdpClient* Instance ;
    bool receiveSuccess;
    QList<double> radiationDataList;

};
#endif // CPSUDPCLIENT_H
